<html>
<head><meta charset="utf-8"><title>Always positive signed integer niche · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html">Always positive signed integer niche</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239871645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239871645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239871645">(May 22 2021 at 13:04)</a>:</h4>
<p>Hey, is there a way on stable to create a always positive signed integer type such that <code>Option&lt;T&gt;</code> is a single byte? Similar to <code>Option&lt;File&gt;</code> on Unix, but ideally cross platform.</p>



<a name="239871802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239871802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239871802">(May 22 2021 at 13:08)</a>:</h4>
<p>Maybe <a href="https://doc.rust-lang.org/std/num/struct.NonZeroI8.html">std::num::NonZeroI8</a> ?</p>
<blockquote>
<p>This enables some memory layout optimization. For example, Option&lt;NonZeroI8&gt; is the same size as i8:<br>
    assert_eq!(size_of::&lt;Option&lt;core::num::NonZeroI8&gt;&gt;(), size_of::&lt;i8&gt;());</p>
</blockquote>



<a name="239872194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872194">(May 22 2021 at 13:15)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> in general the mechanism NonZero* uses is unstable, so you can't create your own custom valid ranges except on nightly</p>



<a name="239872295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872295">(May 22 2021 at 13:17)</a>:</h4>
<p><span class="user-mention" data-user-id="327095">@Urgau</span> That does achieve the same size, but I am actually interested in 0, not just the size.</p>



<a name="239872399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872399">(May 22 2021 at 13:19)</a>:</h4>
<p>Basically I want an index into an array where<code>Option&lt;Index&gt;</code> is a single byte.</p>



<a name="239872592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872592">(May 22 2021 at 13:22)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> I know the mechanism is unstable, but I was wondering if someone had a type hack (like a life hack but for types) that achieves it somehow.</p>



<a name="239872762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872762">(May 22 2021 at 13:25)</a>:</h4>
<p>you could use the nonzerou8 and then add an offset? 1 means 0 etc.</p>



<a name="239872818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872818">(May 22 2021 at 13:26)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> You can already use this <code>Option&lt;core::num::NonZeroI8&gt;</code> where <code>0</code> is <code>Option::None</code>.</p>



<a name="239872859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872859">(May 22 2021 at 13:27)</a>:</h4>
<p><span class="user-mention" data-user-id="327095">@Urgau</span> I want <code>-1</code> to be <code>None</code>.</p>



<a name="239872923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872923">(May 22 2021 at 13:28)</a>:</h4>
<p><span class="user-mention" data-user-id="330154">@The 8472</span> Yeah, but that would add and <code>add</code> instruction to every index which would be a lot.</p>



<a name="239872940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239872940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239872940">(May 22 2021 at 13:29)</a>:</h4>
<p>Oh, that's tricky.</p>



<a name="239873028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239873028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239873028">(May 22 2021 at 13:30)</a>:</h4>
<p>Perhaps a C-style enum could work on stable? you'd have to generate 255 variants</p>



<a name="239873038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239873038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239873038">(May 22 2021 at 13:30)</a>:</h4>
<p>Well not a lot relatively, but by having the niche, I’m trying to have as minimal overhead as possible.</p>



<a name="239873068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239873068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239873068">(May 22 2021 at 13:31)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> Are those attributes documented anywhere by the way?</p>



<a name="239876209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239876209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239876209">(May 22 2021 at 14:24)</a>:</h4>
<p><code>rustc_</code> attributes rarely are AFAIK as they're an implementation detail.</p>



<a name="239878809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239878809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239878809">(May 22 2021 at 15:03)</a>:</h4>
<p>seems unlikely to be documented, but it's <code>rustc_layout_scalar_valid_range_start</code> and <code>rustc_layout_scalar_valid_range_end</code> (with some details in the PR <a href="https://github.com/rust-lang/rust/pull/74699">https://github.com/rust-lang/rust/pull/74699</a> about the -1 niche for file descriptors like your use-case)</p>



<a name="239886543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239886543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239886543">(May 22 2021 at 17:08)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span> Thanks for the link! That will help.</p>



<a name="239886666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239886666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239886666">(May 22 2021 at 17:09)</a>:</h4>
<p>So what you actually want instead of i32 is u31, I guess?</p>



<a name="239889133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239889133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239889133">(May 22 2021 at 17:55)</a>:</h4>
<p>niches don't have to consume entire bits. they only need a single value.</p>



<a name="239889141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239889141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239889141">(May 22 2021 at 17:55)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> Exactly, or an i64 that is really u63.</p>



<a name="239889883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239889883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239889883">(May 22 2021 at 18:07)</a>:</h4>
<p>I would love to have an "isize but only the non-negative parts" (aka "usize but without the top bit set") type.</p>
<p>That's all that can be used for (non-ZST) indexing anyway, and it keeps coming up as people wanting it for data structures.  <code>rustc_datastructures</code> wanted it for <code>Id</code>s at one point, and the Bevy game engine is currently experimenting with using the "use a <code>NonZeroUSize</code> that stores the ones complement" hack to do this same thing.</p>



<a name="239893456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239893456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239893456">(May 22 2021 at 19:07)</a>:</h4>
<p>on many platforms references to non-ZSTs could have their top bit available for niches too. but last time I tried to naively hack that into the layouts it triggered LLVM asserts because some canonicalizations(?) didn't work out as it expected</p>



<a name="239898059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239898059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239898059">(May 22 2021 at 20:29)</a>:</h4>
<p>that's tricky because it's not really guaranteed. stuff like 5-level page tables, or aarch64 pointer authentication break it</p>



<a name="239899443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239899443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239899443">(May 22 2021 at 20:53)</a>:</h4>
<p>For more reference niches, I think I'd start with making 0..align a niche instead of the current situation where only 0..1 is the niche.  That would give slightly more space, can't break anything since it's already clearly UB, and doesn't need discontiguous niche support in the compiler.</p>



<a name="239902022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239902022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> somewheve <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239902022">(May 22 2021 at 21:39)</a>:</h4>
<p><a href="https://users.rust-lang.org/t/how-to-get-the-output-file-path-in-env/60155">https://users.rust-lang.org/t/how-to-get-the-output-file-path-in-env/60155</a></p>



<a name="239902121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239902121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> somewheve <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239902121">(May 22 2021 at 21:40)</a>:</h4>
<p>feel confused about how the get the dir path of <code>exe</code></p>



<a name="239902149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239902149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> somewheve <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239902149">(May 22 2021 at 21:41)</a>:</h4>
<p>anyone can help me ?  i want  to  copy some to  the  dir  in <a href="http://build.rs">build.rs</a></p>



<a name="239902875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239902875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239902875">(May 22 2021 at 21:54)</a>:</h4>
<p>I think you should make a new thread for your question, or perhaps someone can move this to a new thread</p>



<a name="239903125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903125">(May 22 2021 at 21:59)</a>:</h4>
<p><span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span>  at least on linux in userspace the upper half should belong to the kernel so allocators will never return a pointer to it. Only applies to non-0 types of course.</p>



<a name="239903151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903151">(May 22 2021 at 21:59)</a>:</h4>
<p>The upper half gives you 1 bit tho. Also rust has to work in the kernel.</p>



<a name="239903181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903181">(May 22 2021 at 22:00)</a>:</h4>
<p>1 bit = 2^63 niches.</p>



<a name="239903248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903248">(May 22 2021 at 22:00)</a>:</h4>
<p>and rust-in-the-kernel is a different platform. this would be a platform-specific optimization.</p>



<a name="239903259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903259">(May 22 2021 at 22:00)</a>:</h4>
<p>fair enough. I think low alignment bits are more fruitful tbh, it's already expected that they're used, and work everywhere</p>



<a name="239903305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903305">(May 22 2021 at 22:01)</a>:</h4>
<p>I have recently tried to implement that and it causes loads of problems</p>



<a name="239903309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903309">(May 22 2021 at 22:01)</a>:</h4>
<p>I thought initially you meant the ~16 bits available at the top of pointers on most 64 bit platforms</p>



<a name="239903377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903377">(May 22 2021 at 22:02)</a>:</h4>
<p>it probably requires a significant refactoring of the type layout code, splitting it into multiple queries, somehow without losing performance</p>



<a name="239903491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239903491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239903491">(May 22 2021 at 22:03)</a>:</h4>
<p>conservatively checking whether a type is ZST might be easier to determine than getting its alignment which might depend on generics.</p>



<a name="239907508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/239907508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#239907508">(May 22 2021 at 23:18)</a>:</h4>
<p>niches should only matter in layout, where it's always working on concrete types anyway, though, no?</p>
<p>(In the way that <code>size_of::&lt;T&gt;()</code> already doesn't really work normally in const generics, and I don't think this one would make fixing that any harder)</p>



<a name="241673103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/241673103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Demi Obenour <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#241673103">(Jun 06 2021 at 05:00)</a>:</h4>
<p>It is actually possible to have 0 be a valid address on embedded devices!</p>



<a name="241674909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/241674909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#241674909">(Jun 06 2021 at 05:50)</a>:</h4>
<p>and wasm</p>



<a name="241684472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/241684472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#241684472">(Jun 06 2021 at 10:16)</a>:</h4>
<p>Like I said, niches-in-references would be a platform-dependent optimization.</p>



<a name="241685771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/241685771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#241685771">(Jun 06 2021 at 10:51)</a>:</h4>
<p>0 is an invalid reference on any platform, even if the address is accessible</p>



<a name="241696783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/241696783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#241696783">(Jun 06 2021 at 15:27)</a>:</h4>
<p>one step farther, &lt;<code>align_of::&lt;T&gt;()</code> is a niche for references on all platforms, as is all other non-aligned values, so you can always use the lowest X-many bits worth of niches.</p>



<a name="241696891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/241696891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#241696891">(Jun 06 2021 at 15:30)</a>:</h4>
<p>it's UB to set those bits, but they're not used as a niche for layout optimizations at the moment</p>



<a name="241697259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Always%20positive%20signed%20integer%20niche/near/241697259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Always.20positive.20signed.20integer.20niche.html#241697259">(Jun 06 2021 at 15:40)</a>:</h4>
<p>Ah, right, i should say they <em>could be</em> a niche.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>